<?php
/**
 * Created by Command.
 * User: Vito
 */

namespace app\admin\curd\system_auth;

use app\common\curd\Change;
use app\exception\MessageException;
use app\admin\curd\system_role\SystemRoleTrait;
use think\Model;

class SystemAuthChange extends Change
{
    use SystemRoleTrait;

    //允许修改的字段
    protected $field = ['status'];
    //排除的数据
    protected $exclude = [];
    //条件
    protected $where = [];

    protected function saveMiddleware($next, Model $model, array $params)
    {
        $ids = $this->getHasAuthId();

        if (is_array($ids) && !in_array($model->id, $ids)) {
            throw new MessageException('无权限修改');
        }

        return parent::saveMiddleware($next, $model, $params); // TODO: Change the autogenerated stub
    }
}
